﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MapperTests
{
    public class When_mapping_between_fields
    {
        public class DomainPerson
        {
            public String Name { get; set; }
            public String FieldName;
        }

        public class GuiPerson
        {
            public String Name;
        }

        [Fact]
        public void Should_map_between_fields()
        {
            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain=>domain.FieldName,gui=>gui.Name);
            var domainPerson = new DomainPerson {FieldName = "Name from field"};
            var guiPerson = mapping.Map(domainPerson, new GuiPerson());
            Assert.Equal("Name from field",guiPerson.Name);
        }

        [Fact]
        public void Should_map_between_fields_and_properties()
        {
            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.Name, gui => gui.Name);
            var domainPerson = new DomainPerson { Name = "Name from property" };
            var guiPerson = mapping.Map(domainPerson, new GuiPerson());
            Assert.Equal("Name from property", guiPerson.Name);
        }
    }
}
